package cn.skyclass.beans
{
	import cn.skyclass.utils.PathUtil;
	
	import flash.net.FileReference;
	
	/**
	 * 基本的文件信息，提供常用的关于文件的一些属性
	 */
	[Bindable]
	[RemoteClass(alias="cn.skyclass.beans.BaseFileBean")]
	public class BaseFileBean extends BaseExBean implements IUploadFileBean
	{
		override public function init(arg:Object=null):void{
			super.init(arg);	
			
			this.creationTime = new Date();
			this.modificationTime = new Date();		
		}	
			
		override public function validate(arg:Object=null):String{
			this.modificationTime = new Date();
			if(!extensionName){
				this.extensionName = PathUtil.getFileExtensionName(this.originalFileName);
			}
			
			return super.validate(arg);
		}
		
		[Transient]
		override public function get label():String{
			return this.originalFileName;
		}
		
		
		// implements IUploadFileBean method
		public function setPropertiesWithRef(fileRef:FileReference):void{
			this.originalFileName = fileRef.name;
			this.fileSize = fileRef.size;
			this.extensionName = PathUtil.getFileExtensionName(fileRef.name);
			this.guidFileName = PathUtil.generateGuidFileName(extensionName);
			this.physicalFilePath = this.guidFileName;
			this.uploadedNewFile = true;
		}
		
		
		// implements IUploadFileBean props
		private var _guidFileName:String;
		public function get guidFileName():String{
			return this._guidFileName;
		}
		public function set guidFileName(value:String):void{
			this._guidFileName = value;
		}

		private var _uploadedNewFile:Boolean;		
		public function get uploadedNewFile():Boolean{
			return this._uploadedNewFile;
		}
		public function set uploadedNewFile(value:Boolean):void{
			this._uploadedNewFile = value;
		}
		
						
		public var creatorId:int;
		public var creatorNumber:String;
		public var creatorName:String;
		public var creationTime:Date;
		public var modificationTime:Date;
		
		public var extensionName:String;
		public var fileSize:Number = 0;
		public var originalFileName:String;
		public var physicalFilePath:String;
	}
}